s<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>商户管理</cite></a>
        <a><cite>修改代理商</cite></a>
    </div>
</div>

<style>
    .layui-form-label {
        width:15% !important;
        margin-left:1%;
    }
    .layui-input-inline {
        width: 33% !important;
    }
</style>
<div class="layui-fluid">s
    <div class="layui-card">
        <form class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                </ul>
                <input type="hidden" id="agentId" name="agentId" class="layui-input">
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">代理商名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="agentName" name="agentName" lay-verify="required" placeholder="输入代理商名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">所属总代理</label>
                        <div class="layui-input-inline">
	                        <select name="parentAgentId" id="parentAgentId" lay-search="">
		                      <option value="0">请选择</option>
		                    </select>
	                    </div>
                    </div>
                    <div class="layui-form-item">
                    	<label class="layui-form-label">用户登录名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="userName" name="userName" lay-verify="required" placeholder="输入用户登录名" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">真实姓名</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="realName" name="realName" lay-verify="required" placeholder="输入真实姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                    	<label class="layui-form-label">身份证号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="idCard" name="idCard" lay-verify="required" placeholder="输入身份证号" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="mobile" name="mobile" lay-verify="phone" placeholder="输入手机号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">座机号码</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="tel" name="tel" placeholder="输入座机号" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">QQ号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="qq" name="qq" lay-verify="number" placeholder="输入QQ号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                    	<label class="layui-form-label">邮箱</label>
                        <div class="layui-input-inline">
                            <input type="text" id="email" name="email" lay-verify="email" placeholder="输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">通讯地址</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="address" name="address" placeholder="输入通讯地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                    	<label class="layui-form-label">线下充值费率(%)</label>
                        <div class="layui-input-inline">
                            <input type="text" id="offRechargeRate" name="offRechargeRate" lay-verify="number" placeholder="输入线下充值费率" autocomplete="off" class="layui-input" value="0">
                        </div>
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="status" value="1" title="启用" checked="checked">
                            <input type="radio" name="status" value="0" title="停止">
                        </div>
                    </div>
                </div>
                <ul class="layui-tab-title">
                    <li class="layui-this">银行账号</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">开户行名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="bankName" name="bankName" lay-verify="required" placeholder="输入开户行名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">开户网点名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="bankNetName" name="bankNetName" lay-verify="required" placeholder="输入开户网点名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">账户名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="accountName" name="accountName" lay-verify="required" placeholder="输入账户名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">账户号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="accountNo" name="accountNo" lay-verify="required" placeholder="输入账户号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开户所在省</label>
                        <div class="layui-input-inline">
                            <input type="text" id="province" name="province" lay-verify="required" placeholder="输入开户行所在省" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">开户所在市</label>
                        <div class="layui-input-inline">
                            <input type="text" id="city" name="city" lay-verify="required" placeholder="输入开户行所在市" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <ul class="layui-tab-title">
                    <li class="layui-this">安全信息</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">谷歌验证</label>
                        <div class="layui-input-inline">
                            <div id="googleAuthBind" style="display: none">
                                <input type="radio" title="已绑定" checked="checked" disabled>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="untieGoogleAuth">解除绑定</button>
                            </div>
                            <div id="googleAuthNotBind" style="display: none; color: orangered">
                                <input type="radio" title="未绑定" checked="checked" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录安全类型</label>
                        <div class="layui-input-inline">
                            <select id="loginSecurityType" name="loginSecurityType" lay-verify="required">
                                <option value="1">仅登录密码验证</option>
                                <option value="2">登录密码+谷歌组合验证</option>
                            </select>
                        </div>
                        <label class="layui-form-label">支付安全类型</label>
                        <div class="layui-input-inline">
                            <select id="paySecurityType" name="paySecurityType" lay-verify="required">
                                <option value="0">无需验证</option>
                                <option value="1">仅支付密码验证</option>
                                <option value="2">仅谷歌验证</option>
                                <option value="3">支付密码+谷歌组合验证</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录密码</label>
                        <div class="layui-input-inline">
                            <input type="password" required name="password" placeholder="若修改请输入新密码,8-16位的字母和数字组合" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">支付密码</label>
                        <div class="layui-input-inline">
                            <input type="password" required name="payPassword" placeholder="若修改请输入新密码,8-16位的字母和数字组合" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="padding-bottom: 20px;">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="agentEdit">保存</button>
                        <a class="layui-btn" lay-href="agent/list/">返回</a>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['admin', 'form'],function(){
        var form = layui.form
        ,$ = layui.$
        ,admin = layui.admin
        ,element = layui.element
        ,layer = layui.layer ;
        // 导航
        element.render('breadcrumb', 'breadcrumb');
        var router = layui.router();
        var agentId = router.search.agentId;
        
        admin.req({
            type: "POST",
            url: layui.setter.baseUrl + '/agent_info/getParentAgentId',
            data: {agentLevel: "1"},
            success: function(res){
                if(res.code == 0) {
                	var agentList = res.data;
                	//遍历赋值
			        for(var i in agentList){
			          $("#parentAgentId").append('<option value= '+agentList[i].agentId+'>'+agentList[i].agentName+'</option>');
			        }
			        form.render('select');
			        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/agent_info/get',
            data: {
                agentId : agentId
            },
            error: function(err){
                layer.alert(JSON.stringify(err.field), {
                    title: '错误提示'
                })
            },
            success: function(res){
                if(res.code == 0){
                    $('#agentId').val(res.data.agentId);
                    $('#parentAgentId').val(res.data.parentAgentId);
                    $('#agentName').val(res.data.agentName);
                    $('#userName').val(res.data.userName);
                    $('#email').val(res.data.email);
                    $('#mobile').val(res.data.mobile);
                    if(res.data.status == 1) {
                        $("input[name='status'][value='1']").attr("checked",true);
                    }else {
                        $("input[name='status'][value='0']").attr("checked",true);
                    }
                    $('#tel').val(res.data.tel);
                    $('#realName').val(res.data.realName);
                    $('#idCard').val(res.data.idCard);
                    $('#qq').val(res.data.qq);
                    $('#address').val(res.data.address);
                    $('#bankName').val(res.data.bankName);
                    $('#bankNetName').val(res.data.bankNetName);
                    $('#accountName').val(res.data.accountName);
                    $('#accountNo').val(res.data.accountNo);
                    $('#province').val(res.data.province);
                    $('#city').val(res.data.city);
                    $('#offRechargeRate').val(res.data.offRechargeRate);
                    if(res.data.googleAuthStatus == 1) {
                        $("#googleAuthBind").show();
                        $("#googleAuthNotBind").hide();
                    }else {
                        $("#googleAuthBind").hide();
                        $("#googleAuthNotBind").show();
                    }
                    $("#loginSecurityType option[value='"+res.data.loginSecurityType+"']").attr("selected", true);
                    $("#paySecurityType option[value='"+res.data.paySecurityType+"']").attr("selected", true);
                    form.render();
                }
            }
        });
                }
            }
        });

        // 解除谷歌绑定
        $('#untieGoogleAuth').click(function() {
            layer.confirm('确认解绑该用户谷歌验证么?', function(index){
                admin.req({
                    type: "POST",
                    url: layui.setter.baseUrl + '/agent_info/google_untie',
                    data: {
                        agentId : agentId
                    },
                    success: function(res){
                        if(res.code == 0) {
                            layer.alert(res.msg, {title: "提示"}, function(index){
                                layer.close(index);
                                $("#googleAuthBind").hide();
                                $("#googleAuthNotBind").show();
                            });
                        }
                    }
                });
                layer.close(index);
            });
        });

        form.on('submit(agentEdit)', function(data) {
            //这里可以写ajax方法提交表单
            admin.req({
                type: "POST",
                url: layui.setter.baseUrl + '/agent_info/update',
                data: data.field,
                success: function(res){
                    if(res.code == 0) {
                        layer.alert(res.msg, {title: "提示"}, function(index){
                          layer.close(index);
                          location.href = layui.setter.baseLocal + 'agent/list/';
                        });
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    })
</script>